home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / labutaca.net (ES).ifs < prev    next >
Text File  |  2005-03-13  |  8KB  |  296 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=micmic
  8. Title=labutaca.net
  9. Description=labutaca.net+Google
  10. Site=www.labutaca.net
  11. Language=ES
  12. Version=1.5
  13. Requires=3.5.0
  14. Comments= Author    : micmic   (<link>micmic@dieznet.com</link>) |BetaTester: Macoco   (gracias)
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program labutacaImport;
  23. var
  24.   MovieName: string;
  25. const
  26.   Dominio = 'www.labutaca.net';
  27.   BaseURL1 = 'http://www.google.com/custom?hl=es&ie=ISO-8859-1&cof=&domains=';
  28.   BaseURL2 = '&q=';
  29.   BaseURL3 = '&btnG=B%FAsqueda+en+Google&sitesearch=';
  30.  
  31. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  32. var
  33.   i: Integer;
  34. begin
  35.   result := -1;
  36.   if StartAt < 0 then
  37.     StartAt := 0;
  38.   for i := StartAt to List.Count-1 do
  39.     if Pos(Pattern, List.GetString(i)) <> 0 then
  40.     begin
  41.       result := i;
  42.       Break;
  43.     end;
  44. end;
  45.  
  46. function EliminaInicio(S: string; CR: string): string;
  47. begin
  48.   result := S;
  49.   while Pos(CR, result) = 1 do
  50.   begin
  51.     Delete(result, 1, Length(CR));
  52.   end;
  53. end;
  54.  
  55. function SustitucionReiterada(S: string; Buscado: string; Sustituto: string): string;
  56. var
  57.   InicioPos: Integer;
  58.   Longitud: Integer;
  59.   TextoAntes: string;
  60.   TextoDespues : string;
  61. begin
  62.   result := S;
  63.   Longitud := Length(Buscado);
  64.   InicioPos := Pos(Buscado, result);
  65.   while InicioPos > 0 do
  66.   begin
  67.     TextoAntes := copy(result, 1, InicioPos);
  68.     TextoDespues := copy(result, (InicioPos + Longitud), Length(result));
  69.     result := TextoAntes + TextoDespues;
  70.     InicioPos := Pos(Buscado, result);
  71.   end;
  72. end;
  73.  
  74. function CadenaEntre(var S: string; StartTag: string; EndTag: string): string;
  75. var
  76.   InicioPos: Integer;
  77.   S_Aux: string;
  78. begin
  79.   S_Aux := S;
  80.  
  81.   InicioPos := Pos(StartTag, S_Aux);
  82.   Delete(S_Aux, 1, InicioPos + Length(StartTag) - 1);
  83.   InicioPos := Pos(EndTag, S_Aux);
  84.   result := copy(S_Aux, 1, InicioPos - 1);
  85.   Delete(S_Aux, 1, InicioPos + 1);
  86. end;
  87.  
  88. procedure AnalyzePage(Address: string);
  89. var
  90.   Page: TStringList;
  91.   LineNr: Integer;
  92.   PosIni, PosFin: Integer;
  93.   Line, SubLine: string;
  94.   Title, DirURL: string;
  95.   txtTemp: string;
  96. begin
  97.   Page := TStringList.Create;
  98.   Page.Text := GetPage(Address);
  99.   if Pos('No se encontr≤ ninguna pßgina', Page.Text) > 0 then
  100.   begin
  101.     ShowMessage('No se ha encontrado ning·n artφculo por tφtulo.');
  102.   end else
  103.   begin
  104.     PickTreeClear;
  105.     PickTreeAdd('Resultados de la b·squeda para "' + MovieName + '" (' + Dominio + ') por Google:', '');
  106.    
  107.     Page.Text := StringReplace(Page.Text, '<br>', #13#10);
  108.     Page.Text := StringReplace(Page.Text, '<p class=g>', #13#10 + '<p class=g>');
  109.  
  110.     // buscamos los resultados
  111.     LineNr := 0;
  112.  
  113.     while LineNr < Page.Count do
  114.     begin
  115.       SubLine := Page.GetString(LineNr);
  116.       txtTemp := '<p class=g><a href=';
  117.       PosIni := pos(txtTemp, SubLine);
  118.       if PosIni > 0 then
  119.       begin
  120.         SubLine := Copy(SubLine, PosIni + Length(txtTemp), Length(SubLine));
  121.         txtTemp := '>';
  122.         PosFin := pos(txtTemp, SubLine);
  123.         DirURL := Copy(SubLine, 1, PosFin - 1);
  124.         DirURL := StringReplace(DirURL, '"', '');
  125.        
  126.         SubLine := Copy(SubLine, PosFin + Length(txtTemp), Length(SubLine));
  127.         txtTemp := '</a>';
  128.         PosFin := pos(txtTemp, SubLine);
  129.         Title := Copy(SubLine, 1, PosFin - 1);
  130.         HTMLRemoveTags(Title);
  131.  
  132.         //ShowMessage(Title + '-->' + DirURL);
  133.         PickTreeAdd(Title, DirURL);
  134.       end;
  135.       LineNr := LineNr + 1;
  136.     end;
  137.  
  138.     Page.Free;
  139.     if PickTreeExec(Address) then
  140.       AnalyzeMoviePage(Address);
  141.   end;
  142. end;
  143.  
  144. procedure AnalyzeMoviePage(Address: string);
  145. var
  146.   MoviePage: TStringList;
  147.   LineNr: Integer;
  148.   posIni: Integer;
  149.   LineImg: string;
  150.   Line: string;
  151.   valor: string;
  152.   txttemp: string;
  153. begin
  154.  
  155.   Line := '';
  156.   LineImg := '';
  157.  
  158.   SetField(fieldURL, Address);
  159.  
  160.   MoviePage := TStringList.Create;
  161.   MoviePage.Text := GetPage(Address);
  162.  
  163.   LineNr := FindLine('<title>', MoviePage, 0);
  164.   Line := MoviePage.GetString(LineNr);
  165.   Line := CadenaEntre(Line, '<title>LA BUTACA - ', '</title>');
  166.   SetField(fieldTranslatedTitle, Line);
  167.  
  168.   // eliminamos caracteres de saltos de lφnea y tabulaciones
  169.   // luego eliminamos blancos consecutivos
  170.   MoviePage.Text := StringReplace(MoviePage.Text, #13#10, ' ');
  171.   MoviePage.Text := StringReplace(MoviePage.Text, #9, ' ');
  172.   MoviePage.Text := SustitucionReiterada(MoviePage.Text, '  ', ' ');
  173.  
  174.   Line := MoviePage.Text;
  175.  
  176.   txttemp := 'Ampliar cartel';
  177.   if pos(txttemp, Line) <= 0 then
  178.   begin
  179.     txttemp := 'Direcci≤n';
  180.   end
  181.   if pos(txttemp, Line) > 0 then
  182.   begin
  183.     LineImg := CadenaEntre(Line, '<body>', txttemp);
  184.     Line := CadenaEntre(Line, txttemp, '</body>');
  185.   end
  186.  
  187.   txttemp := 'Direcci≤n:';
  188.   if pos(txttemp, Line) <= 0 then
  189.   begin
  190.     txttemp := 'Direcci≤n y gui≤n:';
  191.   end
  192.   if pos(txttemp, Line) > 0 then
  193.   begin
  194.     valor := CadenaEntre(Line, txttemp, '<br>');
  195.     HTMLRemoveTags(valor);
  196.     SetField(fieldDirector, Trim(valor));
  197.   end
  198.  
  199.   txttemp := 'Paφs:';
  200.   if pos(txttemp, Line) <= 0 then
  201.   begin
  202.     txttemp := 'Paφses:';
  203.   end
  204.   if pos(txttemp, Line) > 0 then
  205.   begin
  206.     valor := CadenaEntre(Line, txttemp, '<br>');
  207.     HTMLRemoveTags(valor);
  208.     SetField(fieldCountry, Trim(valor));
  209.   end
  210.  
  211.   txttemp := 'A±o:';
  212.   if pos(txttemp, Line) > 0 then
  213.   begin
  214.     valor := CadenaEntre(Line, txttemp, '<br>');
  215.     HTMLRemoveTags(valor);
  216.     SetField(fieldYear, Trim(StringReplace(valor, '.', '')));
  217.   end
  218.  
  219.   txttemp := 'Duraci≤n:';
  220.   if pos(txttemp, Line) > 0 then
  221.   begin
  222.     valor := CadenaEntre(Line, txttemp, ' min');
  223.     HTMLRemoveTags(valor);
  224.     SetField(fieldLength, Trim(valor));
  225.   end
  226.  
  227.   txttemp := 'Interpretaci≤n:';
  228.   if pos(txttemp, Line) > 0 then
  229.   begin
  230.     valor := CadenaEntre(Line, txttemp, '<br>');
  231.     HTMLRemoveTags(valor);
  232.     SetField(fieldActors, Trim(valor));
  233.   end
  234.  
  235.   txttemp := 'Producci≤n:';
  236.   if pos(txttemp, Line) > 0 then
  237.   begin
  238.     valor := CadenaEntre(Line, txttemp, '<br>');
  239.     HTMLRemoveTags(valor);
  240.     SetField(fieldProducer, Trim(valor));
  241.   end
  242.  
  243.   txttemp := 'M·sica:';
  244.   if pos(txttemp, Line) > 0 then
  245.   begin
  246.     valor := txttemp + CadenaEntre(Line, txttemp, '<strong>SINOPSIS');
  247.     valor := StringReplace(valor, '<br>', #13#10);
  248.     HTMLRemoveTags(valor);
  249.     SetField(fieldComments, Trim(valor));
  250.   end
  251.  
  252.   txttemp := 'SINOPSIS';
  253.   if pos(txttemp, Line) > 0 then
  254.   begin
  255.     valor := CadenaEntre(Line, txttemp, '<hr');
  256.     HTMLRemoveTags(valor);
  257.     SetField(fieldDescription, Trim(valor));
  258.   end
  259.  
  260.   //lo ultimo la imagen
  261.   txttemp := '../../crt/';
  262.   posIni := pos(txttemp, LineImg);
  263.   if posIni <= 0 then
  264.   begin
  265.     txttemp := '../../fotos/';
  266.     posIni := pos(txttemp, LineImg);
  267.   end
  268.   if posIni > 0 then
  269.   begin
  270.     LineImg := copy(LineImg, posIni, Length(LineImg));
  271.     txttemp := 'jpg';
  272.     posIni := pos(txttemp, LineImg);
  273.     LineImg := copy(LineImg, 1, posIni + 2);
  274.     LineImg := EliminaInicio(Lineimg, '../..');
  275.     if LineImg <> '' then LineImg := 'http://' + Dominio + LineImg;
  276.     GetPicture(LineImg);
  277.   end
  278.  
  279.   MoviePage.Free;
  280.   //DisplayResults;
  281. end;
  282.  
  283. // bmicmic: Bucle Principal
  284. begin
  285.   if CheckVersion(3,5,0) then
  286.   begin
  287.     MovieName := GetField(fieldOriginalTitle);
  288.     if MovieName = '' then MovieName := GetField(fieldTranslatedTitle);
  289.  
  290.     Input('Importar de ' + Dominio + ' (por Google)', 'Introduce el Titulo de la Pelicula:', MovieName);
  291.     AnalyzePage(BaseURL1 + Dominio + BaseURL2 + UrlEncode(MovieName) + BaseURL3 + Dominio);
  292.  
  293.   end else
  294.        ShowMessage('Este script necesita una versi≤n superior de Ant Movie Catalog (al menos la version 3.5.0)');
  295. end.
  296.